Skip to content

refactor(consts): extract hard-coded strings into constants#226

Merged
ryoppippi merged 3 commits intomainfrom
refactor/extract-user-agent-constant
Dec 13, 2025
Merged

refactor(consts): extract hard-coded strings into constants#226
ryoppippi merged 3 commits intomainfrom
refactor/extract-user-agent-constant

Conversation

@ryoppippi
Copy link
Copy Markdown
Contributor

@ryoppippi ryoppippi commented Dec 12, 2025

Summary

Extracts hard-coded strings into shared constants in src/consts.ts for improved maintainability and consistency.

What Changed

  • Added USER_AGENT constant and updated requestBuilder.ts, rpc-client.ts, and utils/errors.ts to use it
  • Updated rpc-client.ts to use existing DEFAULT_BASE_URL constant instead of hard-coded fallback URL

Why

Previously, these values were duplicated across multiple files. Centralising them:

  • Makes future updates simpler (change in one place)
  • Reduces risk of inconsistent values
  • Follows the existing pattern of shared constants in consts.ts

Replace hard-coded 'stackone-ai-node' User-Agent string with a shared
constant to improve maintainability and ensure consistency across the
codebase.

Changes:
- Add USER_AGENT constant to src/consts.ts
- Update requestBuilder.ts to use USER_AGENT constant
- Update rpc-client.ts to use USER_AGENT constant
- Update utils/errors.ts to use USER_AGENT constant
- Update requestBuilder.test.ts to use USER_AGENT constant

This centralises the User-Agent value, making future updates simpler
and reducing the risk of inconsistent values across different modules.
@ryoppippi ryoppippi requested a review from a team as a code owner December 12, 2025 17:04
Copilot AI review requested due to automatic review settings December 12, 2025 17:04
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Dec 12, 2025

Open in StackBlitz

npm i https://pkg.pr.new/StackOneHQ/stackone-ai-node/@stackone/ai@226

commit: 930aa61

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the User-Agent string by extracting the hard-coded 'stackone-ai-node' value into a shared USER_AGENT constant in src/consts.ts. This improves code maintainability by centralizing the value and reducing duplication across multiple files.

  • Introduces USER_AGENT constant in src/consts.ts with appropriate documentation
  • Replaces all hard-coded User-Agent string occurrences across production and test code
  • Maintains consistent behavior while improving code organization

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/consts.ts Defines new USER_AGENT constant with JSDoc comment
src/utils/errors.ts Imports and uses USER_AGENT constant in error message formatting
src/rpc-client.ts Imports and uses USER_AGENT constant in HTTP headers
src/requestBuilder.ts Imports and uses USER_AGENT constant in request headers
src/requestBuilder.test.ts Imports and uses USER_AGENT constant in test assertions

I've completed my review of this pull request. The refactoring is well-executed with the following observations:

Positive aspects:

  • All instances of the hard-coded string have been successfully replaced
  • The constant is properly documented with a JSDoc comment
  • The constant follows the existing naming conventions in consts.ts
  • Test files have been updated to maintain consistency
  • The change is purely a refactoring with no behavioral modifications

No issues found: The code changes are clean, consistent, and properly implemented. All files correctly import and use the new constant, and the refactoring achieves its stated goal of improving maintainability.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

@ryoppippi ryoppippi requested a review from glebedel December 12, 2025 17:07
Replace hard-coded 'https://api.stackone.com' fallback URL with the
DEFAULT_BASE_URL constant from consts.ts for consistency.
@ryoppippi ryoppippi changed the title refactor(consts): extract USER_AGENT string into constant refactor(consts): extract hard-coded strings into constants Dec 12, 2025
Tests should use hard-coded values to properly verify the expected
output rather than referencing the same constant being tested.
@ryoppippi ryoppippi force-pushed the refactor/extract-user-agent-constant branch from b6b0fd7 to 930aa61 Compare December 12, 2025 17:12
Copy link
Copy Markdown
Contributor

@glebedel glebedel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ryoppippi ryoppippi merged commit faf1ac2 into main Dec 13, 2025
9 checks passed
@ryoppippi ryoppippi deleted the refactor/extract-user-agent-constant branch December 13, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants